<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
    <meta charset="utf-8">
    <title>文章管理</title>
    <link rel="stylesheet" href="css/bootstrap.min.css"/>
    <script type="text/javascript" src="js/jquery.min.js"></script>
    <script type="text/javascript" src="js/bootstrap.min.js"></script>
    <script type="text/javascript">

        function doDelete() {
            /* 如果这里弹出的对话框，用户点击的是确定，就马上去请求Servlet。
            */
            var cid = $("input:checkbox:checked").val();
            var flag = confirm("是否确定删除?" + cid);
            if (flag) {
                //表明点了确定。 访问servlet。 在当前标签页上打开 超链接，
                //window.location.href="DeleteServlet?sid="+sid;
                location.href = "DeleteArticleServlet?id=" + cid;
            }
        }

        function Info() {
            //var id = $(obj).attr("id");
            var tableRow = $("input:checkbox:checked")[0].parentElement.parentElement;
            //var id = $("input:checkbox:checked").val();
            //获取表格中的一行数据
            var title = tableRow.cells[1].innerText;
            var cl = tableRow.cells[2].innerText;
            var message = tableRow.cells[6].innerText;
            //alert("=="+title+"=="+cl+"=="+message)
            //向模态框中传值
            $('#title').val(title);
            $('#cl').val(cl);
            $('#message-text').val(message);
        }

    </script>
    <style>
        .table th, .table td {
            text-align: center;
            vertical-align: middle !important;
        }

        .col-md-12 {
            padding-top: 1.25rem;
        }

        .col-md-8 {
            padding-left: 0rem;
        }
    </style>
</head>
<body>
<div class="container-fluid">
    <!-- 标题 -->
    <div class="col-md-11">
        <h3>文章管理</h3>
    </div>
    <div class="divider">
        <HR
                style="FILTER: alpha(opacity = 100, finishopacity = 0, style = 3)"
                width="90%" color=#987cb9 SIZE=3 align=center>
    </div>

    <!-- 标签栏 -->

    <!-- 查询 -->
    <div class="col-md-8">
        <div class="col-lg-4">
            <form method="post" action="SearchServlet">
                <div class="input-group">
                    <span class="input-group-addon" id="basic-addon1">栏目:</span>
                    <input type="text" class="form-control" name="title" placeholder="查询....">
                    <span class="input-group-btn">
						<button class="btn btn-info" type="submit">查询</button>
					</span>
                </div>
            </form>
            <!-- /input-group -->
        </div>
        <!-- /.col-lg-6 -->
    </div>
    <!-- 删除，查看 -->
    <div class="col-md-4 text-right">
        <a id="delete" href="#" class="btn btn-danger" onclick="doDelete()">删除</a>
        <a id="view" class="btn btn-success" data-toggle="modal" data-target="#example" onclick="Info()">查看</a>
    </div>

    <!-- 表格 -->
    <form action="ArticleServlet" method="post">
        <div class="row">
            <div class="col-sm-12 col-md-12">
                <table width="100%"
                       id="table"
                       class="table table-bordered table-striped table-hover">
                    <tr>
                        <td><input type="checkbox"/></td>
                        <td>标题</td>
                        <td>发表时间</td>
                        <td>状态</td>
                        <td>浏览数</td>
                        <td>点赞数</td>
                    </tr>
                    <c:forEach items="${pageBean.list }" var="list">
                        <tr>
                            <td><input type="checkbox" value="${list.aid}"/></td>
                            <td>${list.title }</td>
                            <td>${list.isstime }</td>
                            <td>${list.status }</td>
                            <td>${list.viewcount }</td>
                            <td>${list.like }</td>
                            <td hidden>${list.conten}</td>
                        </tr>
                    </c:forEach>
                </table>
            </div>
        </div>
    </form>
</div>
<%--模态框--%>
<div class="modal fade" id="example" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel">
    <div class="modal-dialog" role="document">
        <div class="modal-content">

            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span>
                </button>
                <h4 class="modal-title" id="exampleModalLabel">文章详情</h4>
            </div>

            <div class="modal-body">
                <form method="post" action="ViewServlet">
                    <div class="form-group">
                        <label for="title" class="control-label">标题:</label>
                        <input type="text" class="form-control" id="title">
                    </div>

                    <div class="form-group">
                        <label for="cl" class="control-label">栏目:</label>
                        <input type="text" class="form-control" id="cl">
                    </div>

                    <div class="form-group">
                        <label for="message-text" class="control-label">内容:</label>
                        <textarea class="form-control" id="message-text"></textarea>
                    </div>
                </form>
            </div>

            <div class="modal-footer ">
                <center>
                    <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                    <!-- <button type="button" class="btn btn-primary">添加</button> -->
                </center>
            </div>
        </div>
    </div>
</div>


<!--分页 -->
<div>
    <nav style="text-align: center;" aria-label="Page navigation" class="navbar-fixed-bottom">
        <ul class="pagination ">

            <c:if test="${pageBean.currentPage !=1 }">
                <li>
                    <a href="ArticleServlet?currentPage=${pageBean.currentPage-1 }" aria-label="Previous">
                        <span aria-hidden="tru">&laquo;上一页</span>
                    </a>
                </li>
            </c:if>

            <li>
                <c:forEach begin="1" end="${pageBean.totalPage }" var="i">
                    <c:if test="${pageBean.currentPage == i }">
                        <a href="#">${i }</a>
                    </c:if>
                    <c:if test="${pageBean.currentPage != i }">
                        <a href="ArticleServlet?currentPage=${i }">${i }</a>
                    </c:if>
                </c:forEach>
            </li>
            <li>
                <c:if test="${pageBean.currentPage !=pageBean.totalPage }">
                    <a href="ArticleServlet?currentPage=${pageBean.currentPage+1 }" aria-label="Next">
                        <span aria-hidden="true">下一页&raquo;</span>
                    </a>
                </c:if>
            </li>
        </ul>
    </nav>
</div>
</body>
</html>